package com.csgc.camera.widget.dialog.base

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes

import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.R


class CommonCenterDialog constructor(context: Context, @StyleRes themeResId: Int = R.style.BaseDialogTheme):
    BaseDialog(context,themeResId) {
    private val containerLayout: ViewGroup? by lazy { findViewById(R.id.ll_ui_container) }
    private val titleView: TextView? by lazy { findViewById(R.id.tv_ui_title) }
    private val cancelView: TextView? by lazy { findViewById(R.id.tv_ui_cancel) }
    private val lineView: View? by lazy { findViewById(R.id.v_ui_line) }
    private val confirmView: TextView? by lazy { findViewById(R.id.tv_ui_confirm) }

    init {
        setContentView(R.layout.ui_common_dialog)
        setWindowAnimations(AnimAction.ANIM_IOS)
        setGravity(Gravity.CENTER)
    }

    fun setCustomView(@LayoutRes id: Int) {
        setCustomView(LayoutInflater.from(context).inflate(id, containerLayout, false))
    }
   private fun setCustomView(view: View?) {
        containerLayout?.addView(view, 1)
    }

    fun setDialogTitle(text: CharSequence?) {
        titleView?.text = text

    }
    fun setDialogTitleGone(){
        titleView?.visibility = View.GONE
    }

    fun setDialogTitle(@StringRes id: Int){
        setDialogTitle(context.getString(id))
    }


    fun setCancel(@StringRes id: Int) {
        return setCancel(context.getString(id))
    }

    fun setCancel(text: CharSequence?){
        cancelView?.text = text
        lineView?.visibility = if (text == null || "" == text.toString()) View.GONE else View.VISIBLE

    }
    fun setCancelColor(color:Int){
        cancelView?.setTextColor(color)
    }

    fun setConfirm(@StringRes id: Int){
         setConfirm(context.getString(id))
    }

    fun setConfirm(text: CharSequence?) {
        confirmView?.text = text

    }

    fun setConfirmListener(click: () -> Unit){
        confirmView?.clickWithTrigger {
            click()
        }
    }

    fun setCancelListener(click: () -> Unit){
        cancelView?.clickWithTrigger {
            click()
        }
    }
}